<?php

class System {

    static $conexao = null;

    public static function getConexao() {
        if (self::$conexao == null) {
            mysql_connect("186.202.152.33", "juventudeslz2", "qwer0123");
            self::$conexao = mysql_select_db("juventudeslz2");
        }
        return self::$conexao;
    }

    /**
     * Função estática para desconectar; 
     */
    public static function desconectar() {
        if (self::getConexao() != null) {
            mysql_close();
        }
    }

    static function showSimpleView($url) {
        $url.=".php";
        header("Location:" . $url);
    }

    static function showViewParameter($url, $params, $values) {
        $urlRest = "?";
        $i = 0;
        foreach ($params as $p) {
            if ($i > 0)
                $urlRest.="&";
            $urlRest.=$p . "=" . $values[$i];
            $i++;
        }
        $url.=".php";

        header("Location:" . $url . $urlRest);
    }

    static function checkRules($nivel) {
        
    }

    static function createSessionDefault() {
        if (session_start()) {
            $usuario = array("id" => "000", "nome" => "Visitante", "nivel" => "0", "desc_nivel" => "Padrão");
            $_SESSION["current_user"] = $usuario;
            return true;
        } else {
            return false;
        }
    }

    static function destroySessionDefault() {
        if (session_start()) {
            if (session_destroy())
                return true;
            else
                return false;
        }else {
            return false;
        }
    }

}

?>
